Attribute VB_Name = "mdlSotrage"
Option Explicit


Public Function GetProductQCKC(ByVal WarehouseID As Long, ByVal ProductID As Long, ByVal SpecID As Long, ByVal Period As String) As Double
Dim SQL As String
Dim Rst As ADODB.Recordset
    
    SQL = sprintf("Select IsNull(Sum(Quantity),0) as QCKC From D_StorageData where left(Period,6)<%s " & _
                "And WarehouseID=%d and ProductID=%d and SpecID=%d ", Period, WarehouseID, ProductID, SpecID)
    Set Rst = UI.Svr.cntMain.Execute(SQL, , adCmdText)
    
    If Not (Rst.BOF And Rst.EOF) Then
        GetProductQCKC = Rst.Fields("QCKC").Value
    Else
        GetProductQCKC = 0
    End If
End Function



Public Function GetProductInSum(ByVal WarehouseID As Long, ByVal ProductID As Long, ByVal SpecID As Long, ByVal Period As String) As Double
Dim SQL As String
Dim Rst As ADODB.Recordset
    
    SQL = sprintf("Select IsNull(Sum(Quantity),0) as InSum From D_StorageData where left(Period,6)=%s " & _
                "And WarehouseID=%d and ProductID=%d and SpecID=%d and BillType=0 ", Period, WarehouseID, ProductID, SpecID)
    Set Rst = UI.Svr.cntMain.Execute(SQL, , adCmdText)
    
    If Not (Rst.BOF And Rst.EOF) Then
        GetProductInSum = Rst.Fields("InSum").Value
    Else
        GetProductInSum = 0
    End If
End Function


Public Function GetProductOutSum(ByVal WarehouseID As Long, ByVal ProductID As Long, ByVal SpecID As Long, ByVal Period As String) As Double
Dim SQL As String
Dim Rst As ADODB.Recordset
    
    SQL = sprintf("Select Isnull(Sum(Quantity),0) as OutSum From D_StorageData where left(Period,6)=%s " & _
                "And WarehouseID=%d and ProductID=%d and SpecID=%d and BillType=1 ", Period, WarehouseID, ProductID, SpecID)
    Set Rst = UI.Svr.cntMain.Execute(SQL, , adCmdText)
    
    If Not (Rst.BOF And Rst.EOF) Then
        GetProductOutSum = Abs(Rst.Fields("OutSum").Value)
    Else
        GetProductOutSum = 0
    End If
End Function


Public Function GetProductBalance(ByVal WarehouseID As Long, ByVal ProductID As Long, ByVal SpecID As Long, ByVal Period As String) As Double
Dim SQL As String
Dim Rst As ADODB.Recordset
    
    SQL = sprintf("Select IsNull(Sum(Quantity),0) as Balance From D_StorageData where left(Period,6)<=%s " & _
                "And WarehouseID=%d and ProductID=%d and SpecID=%d ", Period, WarehouseID, ProductID, SpecID)
    Set Rst = UI.Svr.cntMain.Execute(SQL, , adCmdText)
    
    If Not (Rst.BOF And Rst.EOF) Then
        GetProductBalance = Rst.Fields("Balance").Value
    Else
        GetProductBalance = 0
    End If
End Function


